package com.uvlab.sitespot.io;

import com.uvlab.sitespot.service.JxAppService;
import com.uvlab.sitespot.service.task.JxTask;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.LinkedHashMap;

/**
 * Created by Administrator on 2016/6/16 0016.
 */

@CrossOrigin
@RestController
@RequestMapping(value="/rest/task")
public class JxTaskController {
    @Resource(name = "svc")
	private JxAppService svc;

    @RequestMapping(method = RequestMethod.GET)
    public LinkedHashMap getTasks(){
        return  svc.getTaskService().find();
    }

    @RequestMapping(method = RequestMethod.POST)
    public  void addTasks(@RequestBody JxTask task){
         svc.getTaskService().add(task);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public JxTask getTask(@PathVariable(value = "id")String id){
        return  svc.getTaskService().get(id);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public void deleteTask(@PathVariable(value = "id")String id){
          svc.getTaskService().remove(id);
    }

    @RequestMapping(value = "/{id}",method = RequestMethod.PUT)
    public void updateTask(@PathVariable(value = "id")String id,@RequestBody JxTask task){
        svc.getTaskService().set(id,task);
    }
}
